function curry (func) {
  return function curriedFn(...args) {
    // 判断实参和形参的个数
    if (args.length < func.length) {
      return function () {
        return curriedFn(...args.concat(Array.from(arguments)))
      }
    }
    return func(...args)
  }
}
function add(arr){
   return arr.reduce((acc,item)=>{
        return acc+item
    })
}


function sum(...args){
  var f = function(...nextArgs){
      var allArgs = [...args,...nextArgs];
      return sum(...allArgs);
  }
  f.valueOf = function(){
    return args.reduce((a,b)=>a+b);//在valueOf中计算最后结果
  }
  return f;
}

console.log(sum(1,2,3)(4)(7)(4,7).valueOf());
console.log(sum(1,2,3).valueOf());
